/*
 * EquilibriumProblem.cpp
 *
 *  Created on: 27 Jul 2011
 *      Author: Allan
 */

#include "EquilibriumProblem.h"

EquilibriumProblem::EquilibriumProblem(const MatrixXd& Aii,
	const MatrixXd& uei,
	const MatrixXd& alpha,
	const VectorXd& hj,
	const VectorXd& ln_a,
	const VectorXd& ln_Ke)
: N(ln_a.rows()), Ne(ln_Ke.rows()), Nj(hj.rows()), 
  Aii(Aii), uei(uei), alpha(alpha), hj(hj), ln_a(ln_a), ln_Ke(ln_Ke)
{}

EquilibriumProblem::~EquilibriumProblem()
{}

void
EquilibriumProblem::Function(const VectorXd& n, VectorXd& F)
{
	// Compute the residual vector Fj
	F.segment(00, Nj) = alpha * n - hj;
	
	// Compute the residual vector Fe
	F.segment(Nj, Ne) = uei * ln_a - ln_Ke;
}

void
EquilibriumProblem::Jacobian(const VectorXd& n, MatrixXd& J)
{	
	// Compute the block Jacobian matrix Jji
	J.block(00, 00, Nj, N) = alpha;
	
	// Compute the block Jacobian matrix Jei
	J.block(Nj, 00, Ne, N) = uei * Aii;
}
